﻿using System;
using GalaSoft.MvvmLight;
using StateExample.Model;

namespace StateExample.ViewModel
{
    /// <summary>
    /// This class contains properties that the main View can data bind to.
    /// <para>
    /// Use the <strong>mvvminpc</strong> snippet to add bindable properties to this ViewModel.
    /// </para>
    /// <para>
    /// See http://www.galasoft.ch/mvvm/getstarted
    /// </para>
    /// </summary>
    public class MainViewModel : ViewModelBase
    {
        private readonly IDataService _dataService;


        public const string MessageTextPropertyName = "MessageText";
        private string _messageText = "ok";

        public string MessageText
        {
            get
            {
                return _messageText;
            }

            set
            {
                if (_messageText == value)
                {
                    return;
                }

                _messageText = value;
                RaisePropertyChanged(MessageTextPropertyName);
            }
        }

        /// <summary>
        /// Initializes a new instance of the MainViewModel class.
        /// </summary>
        public MainViewModel(IDataService dataService)
        {
            var dispatcherTimer = new System.Windows.Threading.DispatcherTimer();
            dispatcherTimer.Tick += ((a,b) =>
                                         {
                                             MessageText = MessageText == "ok" ? "hello world" : "ok";
                                         });
            dispatcherTimer.Interval = new TimeSpan(0, 0, 5);
            dispatcherTimer.Start();
            _dataService = dataService;
            _dataService.GetData(
                (item, error) =>
                {
                    if (error != null)
                    {
                        // Report error here
                        return;
                    }

                });
        }

        ////public override void Cleanup()
        ////{
        ////    // Clean up if needed

        ////    base.Cleanup();
        ////}
    }
}